package com.muyu.common.core.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 支付方式
 */
@Getter
public enum PayMethod {
    WECHAT_APP("微信app支付",1, PayChannel.WECHAT),
    ALI_APP("支付宝app支付",2, PayChannel.ALI);

    PayMethod(String name, int code, PayChannel payChannel) {
        this.name = name;
        this.code = code;
        this.payChannel = payChannel;
    }

    private final String name;

    @EnumValue
    @JsonValue
    private final int code;

    private final PayChannel payChannel;


    @JsonCreator
    public static PayMethod getPayChannel(int code) {
        for (PayMethod payMethod : PayMethod.values()) {
            if (payMethod.getCode() == code) {
                return payMethod;
            }
        }
        return null;
    }
}
